﻿#pragma once
#include <define.h>

namespace lt
{
	typedef uint8_t trdid_t;

	const trdid_t default_trdid = 0;

	class engine;

	class subscriber;

	class unsubscriber;

	enum class trend_action_type
	{
		TACT_INVALID,	//横盘
		TACT_UPWARD,	//上升趋势upward
		TACT_DOWNWARD,	//下降趋势
	};

	struct trend_handler
	{
		virtual void on_change(trdid_t id, const code_t& code, trend_action_type type) = 0;
	};

	class trend
	{

	private:

		trdid_t _id;

		engine& _engine;

		std::set<trend_handler*> _all_handler;

	public:
		/*
		 *	初始化事件
		 *	生命周期中只会回调一次
		 */
		void init(subscriber& subr);

		/*
		 *	销毁
		 */
		void destory(unsubscriber& unsubr);

		/*
		* 订阅信号
		*/
		void subscrib_trend(trend_handler* hdl);

		/*
		* 取消订阅
		*/
		void unsubscrib_trend(trend_handler* hdl);

	public:

		trend(trdid_t id, engine& engine);

		~trend();

	protected:

		/*
		 *	初始化事件
		 *	生命周期中只会回调一次
		 */
		virtual void on_init(subscriber& suber) {};

		/*
		 *	销毁
		 */
		virtual void on_destory(unsubscriber& unsuber) {};

		/*
		* 触发
		*/
		void trigger(const code_t& code, trend_action_type type);

	};

}


